package com.qqcy.authservice.controller;

import com.qqcy.authservice.clients.UserClients;
import com.qqcy.loginservice.pojo.User;
import com.qqcy.authservice.util.JwtUtil;
import com.qqcy.authservice.util.XTCSResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * DATE: 2022/1/11
 * Author: huhuan
 */
@RestController
public class LoginController {

    @Autowired
    private JwtUtil jwtUtil;

    @Autowired
    private UserClients userClients;

    @RequestMapping("/auth/login/{uid}")
    public XTCSResult login(@PathVariable("uid") Integer uid) {
//        String ip = IpAddressUtils.getIpAddr(request);
        User user = userClients.findById(uid);

        //将uid加密后得到token
        String token = jwtUtil.createJwt(user.getUid() + "");

        XTCSResult xtcsResult = new XTCSResult();
        xtcsResult.setData(token);
        xtcsResult.setMsg("授权成功！");
        xtcsResult.setStatus(200);

        return xtcsResult;
//        User user = userClients.findById(uid);
        //获取用户信息，比对密码
//        return jwtUtil.createJwt(uid);
    }
}
